const mongoose = require('mongoose');

const meanSchema = new mongoose.Schema({
  type: Number,
  data: String,
});

const articleSchema = new mongoose.Schema({
  title: String,
  pic: String,
  see: Number,
  like: Number,
  userId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User', // 假设 'User' 是你的用户模型名称
  },
  mean: [meanSchema],
  comments:[{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Comment', 
  },],
  create_date: {
    type: Date,
    default: Date.now, // 设置默认值为当前日期时间
  },
  update_date: {
    type: Date,
    default: Date.now, // 设置默认值为当前日期时间
  },
}, {
  toJSON: {
    virtuals: true,
    transform: (doc, ret) => {
      ret.id = ret._id.toString();
      delete ret._id;
    },
  },
  versionKey: false,
});

const Article = mongoose.model('Article', articleSchema);

module.exports = Article;
